package cn.tannn.ops.nginx.service.impl;

import cn.tannn.jdevelops.jpa.service.J2ServiceImpl;
import cn.tannn.ops.nginx.dao.DomainsDao;
import cn.tannn.ops.nginx.entity.Domains;
import cn.tannn.ops.nginx.service.DomainsService;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 域名
 *
 * @author <a href="https://t.tannn.cn/">tan</a>
 * @version V1.0
 * @date 2024/8/22 下午4:21
 */
@Service
public class DomainsServiceImpl extends J2ServiceImpl<DomainsDao, Domains, Long> implements DomainsService {

    public DomainsServiceImpl() {
        super(Domains.class);
    }


    @Override
    public List<Domains> findsWebHookDomains() {
        return getJpaBasicsDao().findByWebhookIdIsNotNull();
    }

    @Override
    public List<Domains> findsWebHookDomainsValid() {
        return  getJpaBasicsDao().findByExpiryAfterGreaterThanEqual(DateTime.now().toDate());
    }

    @Override
    public List<Domains> findsWebHookDomains(Integer expiryDay) {
        if(expiryDay <=0){
            expiryDay = 0;
        }
        DateTime.now().plusDays(expiryDay).toDate();
        return getJpaBasicsDao().findByWebhookIdIsNotNull(expiryDay);
    }
}
